package com.hongyun.tms.common.enums;

import lombok.Getter;

/**
 * 拖轮状态枚举
 * <p>
 * 0适航1不适航2停修
 *
 * @author peng.li
 * @date 2024-09-12
 */
@Getter
public enum TugStatusEnum {
    NORMAL(0, "适航"),
    DESTROY(1, "不适航"),
    REPAIRING(2, "停修"),
    UNKNOWN(3, "未知");

    private final int code;
    private final String desc;

    TugStatusEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static TugStatusEnum fromCode(int code) {
        for (TugStatusEnum status : TugStatusEnum.values()) {
            if (status.getCode() == code) {
                return status;
            }
        }
        return null;
    }

    public static Integer getCodeByDesc(String desc) {
        TugStatusEnum[] tugStatusEnums = values();
        for (TugStatusEnum tugStatusEnum : tugStatusEnums) {
            if (tugStatusEnum.getDesc().equals(desc)) {
                return tugStatusEnum.getCode();
            }
        }
        return null;
    }
}
